<#assign ctx=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改权限</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctx}/static/layuiadmin/layui/css/select.css"/>
</head>
<body>


<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改权限</legend>
</fieldset>

<form id="updateUserRole" class="layui-form" lay-filter="updateUserRole" action="" name="updateUserRole">

    <input type="hidden" id="userId" name="userId" value="">
    <div class="layui-form-item">

        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" id="nickname" name="nickname"  autocomplete="off" class="layui-input" readonly style="width:222px" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">电话号码</label>
        <div class="layui-input-block">
            <input type="text" id="phone" name="phone"  autocomplete="off" class="layui-input" readonly style="width:222px" >
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户角色</label>

            <div class="layui-input-block" >
                <select  name="role" lay-filter="role" id="role" lay-verify="required" class="layui-input" >
                    <option value="0">用户</option>
                    <option value="1">商家</option>
                    <option value="2">管理员</option>
                    <option value="3">校园管理员</option>
                </select>
                <!--<input type="text" name="typeName" placeholder="请输入" autocomplete="off" class="layui-input">-->
            </div>
        </div>
    </div>
    <div id="select" class="layui-form-item" >
        <div class="layui-inline">
            <label class="layui-form-label">学校</label>

            <div class="layui-input-block" style="width:222px">
                <select  xm-select="schoolIdList" lay-filter="schoolIdList" name="schoolIdList"  id="schoolIdList" >
                    <option value="">请选择学校</option>
                </select>
                <!--<input type="text" name="typeName" placeholder="请输入" autocomplete="off" class="layui-input">-->
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <div class="layui-input-block">
            <button id="demo1" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>
<script src="${ctx}/static/layuiadmin/layui/layui.js"></script>
<script src="${ctx}/static/layuiadmin/layui/select.js"></script>
<script type="text/javascript" src="${ctx}/static/jquery/jquery.min.js"></script>
<script>
  //  var formSelects = layui.formSelects
    var ctx = "${ctx}"
    layui.config({
        base: ctx + '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        ,'formSelects': 'select'
    }).use(['index', 'form', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form,
        formSelects = layui.formSelects
            ,upload = layui.upload ;

        layer.ready(function(){
            $.ajax({
                //几个参数需要注意一下
                type: "get",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                // contentType : 'application/json; charset=UTF-8',
                url: ctx +"/school/findAllByDeleted" ,//url
                // async : false,
                data: {
                    deleted:1
                },
                success: function (result) {
                    // console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 1) {
                        for (var i=0;i<result.reObj.length;i++){
                            $('#schoolIdList').append(new Option(result.reObj[i].name,result.reObj[i].id));// 下拉菜单里添加元素

                        }
                        // formSelects.value('schoolIdList',"1,2".split(","))
                        formSelects.render();
                    }
                },
                error : function(e) {
                    layer.msg('出错了');
                }
            });

            setTimeout(function f(){
                $.ajax({
                    //几个参数需要注意一下
                    type: "get",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    // contentType : 'application/json; charset=UTF-8',
                    url: ctx +"/manageSchool/listManageSchool" ,//url
                    // async : false,
                    data: {
                        userId:document.getElementById('userId').value
                    },
                    success: function (result) {
                        // console.log(result);//打印服务端返回的数据(调试用)
                        if (result.code == 1) {
                            // formSelects.value('schoolIdList',"1,2".split(","))
                            var data=result.reObj;
                            var arr=[];
                            for (var i in data ) {
                                arr.push(data[i].schoolId);
                            }
                            formSelects.value('schoolIdList', arr);
                        }
                    },
                    error : function(e) {
                        layer.msg('出错了');
                    }
                });
            },100

        )


        })

        //监听提交
        // $(document).ready(function() {
            // select下拉框选中触发事件
            form.on('select(role)', function(data){
                // alert(data.value); // 获取选中的值
                if (data.value=="3") {
                    $("#select").show();
            }
            });

        // });


    })

</script>
<script type="text/javascript">

    function getData(){
        var data=$("#updateUserRole").serialize();
        return data;
    }
</script>
</body>
</html>